package com.ruoyi.project.module.bodyguard.controller;

import java.util.List;

import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.module.bodyguard.domain.Bodyguard;
import com.ruoyi.project.module.bodyguard.service.IBodyguardService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 保镖简介 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-11-13
 */
@Controller
@RequestMapping("/module/bodyguard")
public class BodyguardController extends BaseController
{
    private String prefix = "module/bodyguard";
	
	@Autowired
	private IBodyguardService bodyguardService;
	
	@RequiresPermissions("module:bodyguard:view")
	@GetMapping()
	public String bodyguard()
	{
	    return prefix + "/bodyguard";
	}
	
	/**
	 * 查询保镖简介列表
	 */
	@RequiresPermissions("module:bodyguard:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Bodyguard bodyguard)
	{
		startPage();
        List<Bodyguard> list = bodyguardService.selectBodyguardList(bodyguard);
		return getDataTable(list);
	}
	@Log(title = "参数管理", businessType = BusinessType.EXPORT)
	@RequiresPermissions("system:bodyguard:export")
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(Bodyguard bodyguard) throws Exception
	{
		try
		{
			List<Bodyguard> list = bodyguardService.selectBodyguardList(bodyguard);
			ExcelUtil<Bodyguard> util = new ExcelUtil<Bodyguard>(Bodyguard.class);
			return util.exportExcel(list, "bodyguard");
		}
		catch (Exception e)
		{
			return error("导出Excel失败，请联系网站管理员！");
		}
	}
	/**
	 * 新增保镖简介
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存保镖简介
	 */
	@RequiresPermissions("module:bodyguard:add")
	@Log(title = "保镖简介", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Bodyguard bodyguard)
	{		
		return toAjax(bodyguardService.insertBodyguard(bodyguard));
	}

	/**
	 * 修改保镖简介
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Integer id, ModelMap mmap)
	{
		Bodyguard bodyguard = bodyguardService.selectBodyguardById(id);
		mmap.put("bodyguard", bodyguard);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存保镖简介
	 */
	@RequiresPermissions("module:bodyguard:edit")
	@Log(title = "保镖简介", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Bodyguard bodyguard)
	{		
		return toAjax(bodyguardService.updateBodyguard(bodyguard));
	}
	
	/**
	 * 删除保镖简介
	 */
	@RequiresPermissions("module:bodyguard:remove")
	@Log(title = "保镖简介", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(bodyguardService.deleteBodyguardByIds(ids));
	}
	
}
